CLASS lhc_zr_ymoon_0020 DEFINITION INHERITING FROM cl_abap_behavior_handler.
  PRIVATE SECTION.

    METHODS get_instance_authorizations FOR INSTANCE AUTHORIZATION
      IMPORTING keys REQUEST requested_authorizations FOR zr_ymoon_0020 RESULT result.

    METHODS create FOR MODIFY
      IMPORTING entities FOR CREATE zr_ymoon_0020.

    METHODS update FOR MODIFY
      IMPORTING entities FOR UPDATE zr_ymoon_0020.

    METHODS delete FOR MODIFY
      IMPORTING keys FOR DELETE zr_ymoon_0020.

    METHODS read FOR READ
      IMPORTING keys FOR READ zr_ymoon_0020 RESULT result.

    METHODS lock FOR LOCK
      IMPORTING keys FOR LOCK zr_ymoon_0020.
    METHODS create_pr FOR MODIFY
      IMPORTING keys FOR ACTION zr_ymoon_0020~create_pr RESULT result.

ENDCLASS.

CLASS lhc_zr_ymoon_0020 IMPLEMENTATION.

  METHOD get_instance_authorizations.
  ENDMETHOD.

  METHOD create.
    DATA lt_create TYPE STANDARD TABLE OF ymoont_0020.
    DATA:lt_c  TYPE TABLE FOR CREATE zr_ymoon_0020 .

    DATA : ls_create TYPE ymoont_0020.


    LOOP AT entities ASSIGNING FIELD-SYMBOL(<fs_line>).
      ls_create = CORRESPONDING #( <fs_line> MAPPING FROM ENTITY USING CONTROL ).
      mapped-zr_ymoon_0020 = VALUE #( BASE mapped-zr_ymoon_0020
                                 ( %cid = <fs_line>-%cid
                                   uuid = ls_create-uuid
                                 ) ).
    ENDLOOP.
*    insert INTO ymoont_0020 VALUES @LS_CREATE.

*    lt_c = entities.
*
*    MODIFY ENTITIES OF zr_ymoon_0020 IN LOCAL MODE
*    ENTITY zr_ymoon_0020
*    CREATE FIELDS ( werks matnr menge meins ) WITH lt_c
*    REPORTED DATA(ls_pr_reported)
*    MAPPED DATA(ls_pr_mapped)
*    FAILED DATA(ls_pr_failed).



    DATA: lt_pr_create   TYPE TABLE FOR CREATE i_purchaserequisitiontp,
          lt_pri_create  TYPE TABLE FOR CREATE i_purchaserequisitiontp\_purchaserequisitionitem,
          lt_pram_create TYPE TABLE FOR CREATE i_purchasereqnitemtp\_purchasereqnacctassgmt,
          lt_prit_create TYPE TABLE FOR CREATE i_purchasereqnitemtp\_purchasereqnitemtext.

    lt_pr_create      =  VALUE #(  ( %cid                    = 'My%CID_1'
                                     purchaserequisitiontype = 'NB' ) ).
    lt_pri_create     =  VALUE #(  ( %cid_ref                = 'My%CID_1'
                                     %target = VALUE #(  (
                                             %cid                            = 'My%ItemCID_1'
                                             plant                           = '4310'
                                             purchaserequisitionitemtext     = 'ASUG2022'
                                             accountassignmentcategory       = 'U'
                                             requestedquantity               = '8.00'
                                             baseunit                        = 'KG'
                                             purchaserequisitionprice        = '10.00'
                                             purreqnitemcurrency             = 'EUR'
                                             materialgroup                   = 'A001'
                                             purchasinggroup                 = '001'
                                             purchasingorganization          = '1010'
                                             material                        = '000000000000000004'
                                                     )  )
                                )  ).
    lt_pram_create    =  VALUE #( (  %cid_ref               = 'My%ItemCID_1'
                                     %target = VALUE #( (
                                            %cid                            = 'My%AccntCID_1'
                                            costcenter                      = 'JMW-COST'
                                            glaccount                       = '0000400000' ) ) ) ).
    lt_prit_create    =  VALUE #( (  %cid_ref               = 'My%ItemCID_1'
                                     %target = VALUE #( (
                                            %cid                            = 'My%TextCID_1'
                                            textobjecttype                  = 'B01'
                                            language                        = 'E'
                                            plainlongtext                   = 'item text created from PAAS API'
                                                        )

                                                        (
                                            %cid             = 'My%TextCID_2'
                                            textobjecttype                  = 'B02'
                                            language                        = 'E'
                                            plainlongtext                   = 'item2 text created from PAAS API'
                                          ) )
                                 )  ).

    MODIFY ENTITIES OF i_purchaserequisitiontp
  ENTITY purchaserequisition CREATE FIELDS ( purchaserequisitiontype ) WITH lt_pr_create

  CREATE BY \_purchaserequisitionitem
  FIELDS (    plant
*                purchaserequisitionitemtext
*                accountassignmentcategory
              requestedquantity
              baseunit
*                purchaserequisitionprice
*                purreqnitemcurrency
*                materialgroup
*                purchasinggroup
*                purchasingorganization
*                multipleacctassgmtdistribution
              material
          )
  WITH lt_pri_create
  REPORTED DATA(ls_pr_reported)
  MAPPED DATA(ls_pr_mapped)
  FAILED DATA(ls_pr_failed).


  ENDMETHOD.

  METHOD update.
  ENDMETHOD.

  METHOD delete.
  ENDMETHOD.

  METHOD read.
    DATA a.
    a = 1.
  ENDMETHOD.

  METHOD lock.
  ENDMETHOD.

  METHOD create_pr.

    DATA a.
    a = 1.

  ENDMETHOD.

ENDCLASS.

CLASS lsc_zr_ymoon_0020 DEFINITION INHERITING FROM cl_abap_behavior_saver.
  PROTECTED SECTION.

    METHODS finalize REDEFINITION.

    METHODS check_before_save REDEFINITION.

    METHODS save REDEFINITION.

    METHODS cleanup REDEFINITION.

    METHODS cleanup_finalize REDEFINITION.

ENDCLASS.

CLASS lsc_zr_ymoon_0020 IMPLEMENTATION.

  METHOD finalize.
  ENDMETHOD.

  METHOD check_before_save.
  ENDMETHOD.

  METHOD save.
  ENDMETHOD.

  METHOD cleanup.
  ENDMETHOD.

  METHOD cleanup_finalize.
  ENDMETHOD.

ENDCLASS.
